<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<title>编辑角色</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css" />
</head>
<body>
	<div id="index-hav2">
		<div class="index-hav-right" id="index-hav-right-clear">
			<div class="row">
				<div class="col-md-9">
					<span id="icon-house"> </span><span id="arrows-left">首页</span> <span
						id="arrows-left">></span><span>系统管理</span> <span id="arrows-left">></span><span>角色管理</span>
				</div>
				<div class="bank-box">
					<div class="lianlian platform">
						<div class="col-md-12" style="margin: 13px 0">
							<form id="defaultForm" class="form-horizontal" method="post" action="<%=path%>/system/role/editRole">
								<input type="hidden" name="id" value="${role.id }">
								<div class="panel panel-default">
									<!--div class="panel-heading">
										<h4 class="panel-title">
											<c:if test="${role.id != null}">编辑角色</c:if>
											<c:if test="${role.id == null}">添加角色</c:if>
										</h4>
									</div-->
									<div class="panel-body">
										<div class="form-group">
											<label class="col-sm-2 control-label">角色名称:</label>
											<div class="col-sm-6">
												<input type="text" name="roleName" class="form-control"
													value="${role.roleName}">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label">角色类型:</label>
											<div class="col-sm-6">
												<select class="form-control input-sm mb15" name="type">
													<option value="1"
														<c:if test="${role.type == '1'}">selected</c:if>>管理员</option>
													<option value="2"
														<c:if test="${role.type == '2'}">selected</c:if>>普通用户</option>
												</select>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label">状态:</label>
											<div class="col-sm-6">
												<select class="form-control input-sm mb15" name="isUsed">
													<option value="1"
														<c:if test="${role.isUsed == '1'}">selected</c:if>>启用</option>
													<option value="0"
														<c:if test="${role.isUsed == '0' }">selected</c:if>>禁用</option>
												</select>
											</div>
										</div>
										<div class="col-sm-8 col-btn-12">
										<button type="sumbit" class="btn btn-primary" id="editRoleBtn">保存</button>
										<!--button type="button" class="clearForm btn btn-default">重置</button  -->
										<button type="button" class="btn btn-default" onclick="window.location.href='<%=path%>/system/role/list'">返回</button>
									</div>
									</div>
									
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="gray-screen"></div>
</body>
<script type="text/javascript" src="<%=basePath%>js/validate/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/rem.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/bootstrapValidator.js"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/zh_CN.js"></script>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/common/dialog.3.1.min.js"></script>
<script type="text/javascript">
		$(document).ready(function(){
			 $('#defaultForm').bootstrapValidator({
		            message: 'This value is not valid',
		            feedbackIcons: {
		                valid: 'glyphicon glyphicon-ok',
		                invalid: 'glyphicon glyphicon-remove',
		                validating: 'glyphicon glyphicon-refresh'
		            },
		            fields: {
		            	roleName: {
		                    validators: {
		                        notEmpty: {},
		                        stringLength: {min: 1,max: 30},
		                    }
		                },
		                type: {
		                    validators: {
		                        notEmpty: {}
		                    }
		                },
		                isUsed: {
		                    validators: {
		                        notEmpty: {}
		                    }
		                },
		            }
		        }).on('success.form.bv', function(e) {
		            // Prevent form submission
		            e.preventDefault();

		            // Get the form instance
		            var $form = $(e.target);

		            // Get the BootstrapValidator instance
		            var bv = $form.data('bootstrapValidator');

		            // Use Ajax to submit form data
		            $.post($form.attr('action'), $form.serialize(), function(result) {

		            	if(result.message != undefined){
				            	var code = result.code;
				            	var grayScreen=document.getElementById("gray-screen"); 
				            	Dialog({
						                "msg": '<div class="D_alert">'+result.message+'</div>',
						                "title": "提示",
						                "showButtons": true,
						                "cancelButton": false,
						                "onComplete": function() {
						                	if(code!=1){
						                		$("body").empty();
							                 	window.location.href='<%=path%>/system/role/list';
						                	}
						                }
						            });	
				          }else{
				        	  window.location.href='<%=path%>/system/role/list';
		                 }
		            }, 'json');
		        });
	           
			//清空搜索条件
			$(".clearForm").click(function(){
				$("#form").find("input").val("");
			});
		});
    </script>
</html>
